package com.demo.schedule;

import com.demo.config.MyMQTTClient;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: 张西华
 * @Date: 2023/03/28 15:34
 * @version: v1.0
 * @Description: TODO
 */
@Slf4j
@Component
public class BusinessInit {

    String suffix = "51";
    String rsu = "leddisplay0_state";

    @Autowired
    private MyMQTTClient myMQTTClient;


    @PostConstruct
    public void init() {

        myMQTTClient.subscribe(rsu + suffix, 0);
    }

    @Scheduled(cron = "0/50 * * * * ?")
    public void rsu() {
        String s1 = "{\n" +
                "  \"html\": \"车道天线正常\",\n" +
                "  \"msgtype\": \"devicestate\",\n" +
                "  \"name\": \"rsu\",\n" +
                "  \"state\": 0\n" +
                "}";
        myMQTTClient.publish(s1, rsu + suffix, 0);
    }
}
